package com.credit.jumu.calculator.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.widget.EditText;
import android.widget.TextView;

import com.credit.jumu.calculator.R;
import com.credit.jumu.calculator.activity.CarResultActivity_;
import com.credit.jumu.calculator.activity.OtherResultActivity;
import com.credit.jumu.calculator.activity.OtherResultActivity_;
import com.credit.jumu.calculator.base.BaseFragment;
import com.credit.jumu.calculator.utils.DensityUtil;
import com.credit.jumu.calculator.utils.LogUtils;
import com.credit.jumu.calculator.utils.StringHandleUtil;
import com.credit.jumu.calculator.utils.ToastUtil;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import cn.qqtheme.framework.picker.OptionPicker;
import cn.qqtheme.framework.widget.WheelView;

/**
 * Created by Administrator on 2017/11/24/024.
 */
//公积金贷
@EFragment(R.layout.fragment_accumulation)
public class AccumulationFragment extends BaseFragment {

	@ViewById
	TextView acctype;
	@ViewById
	EditText commAllmoney, commlilv, commyears;
	int type = 0;
	@Click(R.id.acctype)
	public void chooseFangShi() {
		OptionPicker picker = new OptionPicker(getActivity(), new String[]{
				"等额本息", "等额本金"
		});
		picker.setCycleDisable(true);//设置启用循环
		picker.setLineSpaceMultiplier(1);//总高度(1-4)
		picker.setCanceledOnTouchOutside(false);
		picker.setDividerRatio(WheelView.DividerConfig.FILL);
		picker.setShadowColor(Color.BLACK, 1);//选中的背景色
		picker.setSelectedIndex(0);
		picker.setTopLineColor(getResources().getColor(R.color.transparent));//分割线颜色
		picker.setSubmitTextColor(getResources().getColor(R.color.titlettextbg));//右边文字
		picker.setCancelTextColor(getResources().getColor(R.color.titlettextbg));//左边文字
		picker.setTextSize(DensityUtil.dip2px(getContext(), 7));//文字大小
		picker.setTextColor(getResources().getColor(R.color.back));
		picker.setDividerColor(getResources().getColor(R.color.transparent));
		picker.setTopBackgroundColor(getResources().getColor(R.color.linebg));//顶部背景
		picker.setSubmitText("完成");
		picker.setCanceledOnTouchOutside(true);
		picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
			@Override
			public void onOptionPicked(int index, String item) {
				type = index;
				acctype.setText(item);
			}
		});
		picker.show();
	}


	@Override
	public void onResume() {
		super.onResume();
		LogUtils.println("-----------------------AccumulationFragmentonResume");
		hideKeyboard();
	}

	@Override
	public void onPause() {
		super.onPause();
		LogUtils.println("-----------------------AccumulationFragmentonPause");
	}

	@Override
	public void onStart() {
		super.onStart();
		LogUtils.println("-----------------------AccumulationFragmentonStart");
	}

	@Override
	public void onStop() {
		super.onStop();
		LogUtils.println("-----------------------AccumulationFragmentonStop");
	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		LogUtils.println("-----------------------AccumulationFragmentnChanged");
	}



	@Click(R.id.togetresult)
	public void toResult(){

		double allpic = StringHandleUtil.toInt(commAllmoney.getText().toString());//总金额
		double commlilvs = StringHandleUtil.toInt(commlilv.getText().toString());//利率
		int commyear = StringHandleUtil.toInts(commyears.getText().toString());//年限
		if(allpic<=0||commlilvs<=0||commyear<=0){
			ToastUtil.showShortToast("请先完善信息");
			return;
		}

		Intent intent = new Intent(getActivity(), OtherResultActivity_.class);
		intent.putExtra("allpic", allpic);
		intent.putExtra("commlilvs", commlilvs);//
		intent.putExtra("needyeard", commyear);//
		intent.putExtra("type", type);//
		intent.putExtra("page", 1);//
		startActivity(intent);

//		Intent intent = new Intent(getActivity(), OtherResultActivity_.class);
//		startActivity(intent);
	}

}
